#include <cstdio>
#include <cmath>

int get_root(int num);

int main(int argc, char const *argv[]){
    int input_num;
    while(scanf("%d", &input_num) != EOF){
        int digital_root = input_num;
        while(digital_root > 9)
            digital_root = get_root(digital_root);
        printf("%d\n", digital_root);
    }
    return 0;
}

int get_root(int num){
    int return_num = 0;
    while (num != 0){
        return_num += num % 10;
        num /= 10;
    }
    return return_num;
}